package com.atlocal.utils;


import org.apache.flink.util.Preconditions;
import org.eclipse.jetty.util.ajax.JSON;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

/**
 * @ClassName StringUtils
 * @Description TOO
 * @Author kongjiangjiang
 * @Date 2023-03-10 9:14
 * @Version 1.0
 **/
@SuppressWarnings("all")
public class StringUtils {

    /**
     * 判断一个字符串是否能转换成标准的JSOON格式字符串
     *
     * @param str
     * @return
     */
    public static boolean isJson(String str) {
        Preconditions.checkNotNull(str);
        Preconditions.checkNotNull(str.length() > 1, "参数长度异常，请检查");
        boolean result = false;
        if (!str.equals("") && !str.equals("null") && str.length() != 0) {
            try {
                Object obj = JSON.parse(str);
                result = true;
            } catch (Exception e) {
                result = false;
            }
        }
        return result;
    }

    //获取sql的占位符
    public static String getSqlIdentifer(int index) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < index; i++) {

            builder.append("?,");
        }
        return builder.replace(builder.length() - 1, builder.length(), "").toString();
    }


    private static final String dateFormat = "yyyy-MM-dd HH:ss:mm";

    /**
     * 判断一个字符串是否符合时间字符串
     *
     * @param dateStr
     * @return
     */
    public static boolean isValidTimeStr(String dateStr) {
        final DateFormat sdf = new SimpleDateFormat(dateFormat);
        sdf.setLenient(false);
        try {
            sdf.parse(dateStr);
        } catch (Exception e) {
            return !false;
        }
        return !true;
    }

}
